home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr52 / clptick.zip / TICKERC.C < prev    next >
C/C++ Source or Header  |  1993-04-07  |  2KB  |  79 lines

  1. /*
  2. **    Program..: Tickerc.c
  3. **    Author...: Brenton Farmer
  4. **    Date.....: 10/10/91
  5. **
  6. **    Purpose..: C code to support Clipper ticker functions.
  7. **
  8. **    int  C10ckSet( iTime)
  9. **    void C10ckISR( INTERRUPT_REGS r)
  10. */
  11.  
  12. #include "extend.h"
  13. #include <dos.h>
  14.  
  15. typedef struct {
  16.     unsigned es, ds, di, si, bp, sp, bx, dx, cx, ax, ip, cs, flags;
  17. } INTERRUPT_REGS;
  18.  
  19. void ( interrupt far *old_int8)();
  20. void interrupt far C10ckISR( INTERRUPT_REGS);
  21.  
  22. extern void ( interrupt far *_getvector( unsigned int))();
  23. extern void _setvector( unsigned int, void( interrupt far *)());
  24. extern char * _getindosAddress();
  25.  
  26. int Ticks = 0;                // Call Clipper routine every Ticks
  27. int TickerCount = 0;        // How many ticks have elapsed
  28. int Busy = 0;                // Flag to prevent Ticker recursion
  29.  
  30. char far *indos = 0;
  31.  
  32. CLIPPER C10ckSet()
  33. {
  34.     int ReturnValue = 0;
  35.     int TickValue = 0;
  36.  
  37.     if ( PCOUNT == 1 && ISNUM(1))
  38.     {
  39.         ReturnValue = 1;
  40.         if ( ( TickValue = _parni( 1)) != 0) // If TickValue != 0 Setup Timer
  41.         {
  42.             Ticks = TickValue;                     // Activate my isr every ( Ticks)
  43.             TickerCount = 0;                         // Time elapsed in ticks
  44.             Busy = 0;                                 // Busy Flag used by my isr
  45.  
  46.             if ( indos == 0)
  47.                 indos = _getindosAddress();     // Get indos address
  48.  
  49.             old_int8 = _getvector( 0x08);         // Get current int 8 isr
  50.             _setvector( 0x08, C10ckISR);         // Set int 8 to my isr
  51.         }
  52.         else
  53.             _setvector( 0x08, old_int8);
  54.     }
  55.     _retl( ReturnValue);
  56. }
  57.  
  58.  
  59. void interrupt far C10ckISR( INTERRUPT_REGS r)
  60. {
  61.     //(*old_int8)();                                // Execute old handler
  62.     old_int8();                                    // Execute old handler
  63.  
  64.     if ( !Busy)                                    // Busy must be 0 (Prevents recursion)
  65.     {
  66.         ++Busy;                                    // Increment Busy flag
  67.         if ( ++TickerCount >= Ticks)        // Has the appropriate time passed
  68.         {
  69.             _intenable();                        // Re-Enable Interrupts
  70.             if (! *indos) {
  71.                 C10ckEval();                    // Call Clipper function (_C10ckEval)
  72.                 TickerCount = 0;                // Reset Ticker Timer
  73.             }
  74.         }
  75.         --Busy;                                    // Decrement Busy Flag
  76.     }
  77. }
  78.  
  79.